Docker-Compose搭建kafka

kafka-compose.yml 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#docker-compose -f kafka-compose.yml up -d
#kafka-compose.yml 配置文件如下
version: '3'
services:
kafka:
container_name: kafka
image: wurstmeister/kafka:2.13-2.6.0
ports:
- "9092:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: 192.168.23.128 # need to be replaced with host ip 替换为宿主机IP
advertised.listeners: PLAINTEXT://192.168.23.128:9092 # need to be replaced with host ip 替换为宿主机IP
volumes:
- /var/run/docker.sock:/var/run/docker.sock # 容器内可以执行docker ps、docker port等命令
restart: always

zookeeper:
container_name: zookeeper
image: wurstmeister/zookeeper
ports:
- "2181:2181"
restart: always

注意:
1.KAFKA_ADVERTISED_HOST_NAME 替换为宿主机IP
2.advertised.listeners 替换为宿主机IP
3.此镜像版本,kafka默认占用1G内存,若启动不了,请检查内存足够

kafkaui-compose.yml 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#docker-compose -f kafkaui-compose.yml up -d
#kafkaui-compose.yml 配置文件如下
version: '3.0'
services:
kafka-ui:
image: provectuslabs/kafka-ui:master
container_name: kafka-ui
ports:
- 18080:8080
restart: always
environment:
- KAFKA_CLUSTERS_0_NAME=douyh
- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=192.168.23.128:9092
# - KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL=SASL_PLAINTEXT
# - KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM=PLAIN
# - KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG=org.apache.kafka.common.security.plain.PlainLoginModule required username="app" password="xxxxxxxx";
# - KAFKA_CLUSTERS_0_PROPERTIES_PROTOCOL=SASL
- AUTH_TYPE="LOGIN_FORM"
- SPRING_SECURITY_USER_NAME=root
- SPRING_SECURITY_USER_PASSWORD=root

注意:
1.KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS 替换为宿主机IP

在外部浏览器可以访问 http://ip:18080/
账号:root,
密码:root

一辈子很短,努力的做好两件事就好;
第一件事是热爱生活,好好的去爱身边的人;
第二件事是努力学习,在工作中取得不一样的成绩,实现自己的价值,而不是仅仅为了赚钱;

继开 wechat
欢迎加我的微信,共同交流技术